home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / AmigaEYE_V39.7 / ScreenNotifly.lha / ScreenNotify / src / screennotifytest.c < prev   
C/C++ Source or Header  |  1995-03-26  |  3KB  |  121 lines

  1. #include <libraries/screennotify.h>
  2. #include <clib/dos_protos.h>
  3. #include <clib/exec_protos.h>
  4. #include <clib/intuition_protos.h>
  5. #include <clib/screennotify_protos.h>
  6. #include <pragmas/dos_pragmas.h>
  7. #include <pragmas/exec_pragmas.h>
  8. #include <pragmas/intuition_pragmas.h>
  9. #include <pragmas/screennotify_pragmas.h>
  10. #include <stdlib.h>
  11.  
  12. extern struct Library *SysBase, *DOSBase, *IntuitionBase;
  13.  
  14. /* Create a test window on the Workbench screen */
  15. static struct Window *CreateWindow(void)
  16. {
  17.  return(OpenWindowTags(NULL, WA_Width,         200,
  18.                              WA_Height,        100,
  19.                              WA_Flags,         WFLG_CLOSEGADGET | WFLG_DRAGBAR,
  20.                              WA_IDCMP,         IDCMP_CLOSEWINDOW,
  21.                              WA_PubScreenName, "Workbench",
  22.                              WA_Title,         "ScreenNotify Test",
  23.                              TAG_DONE));
  24. }
  25.  
  26. /* Main program */
  27. int main(int argc, char **argv)
  28. {
  29.  struct Library *ScreenNotifyBase;
  30.  
  31.  /* Open screennotify.library */
  32.  if (ScreenNotifyBase = OpenLibrary(SCREENNOTIFY_NAME, SCREENNOTIFY_VERSION)) {
  33.   struct MsgPort *p;
  34.  
  35.   /* Create message port for ScreenNotify notifications */
  36.   if (p = CreateMsgPort()) {
  37.    APTR handle;
  38.  
  39.    /* Add our program as WB client */
  40.    if (handle = AddWorkbenchClient(p, 0)) {
  41.     struct Window *w;
  42.  
  43.     /* Open window */
  44.     if (w = CreateWindow()) {
  45.      ULONG portmask, winmask;
  46.      BOOL active = TRUE;
  47.  
  48.      /* Calculate signal masks */
  49.      portmask = 1L << p->mp_SigBit;
  50.      winmask  = 1L << w->UserPort->mp_SigBit;
  51.  
  52.      /* Event loop */
  53.      while (active) {
  54.       ULONG sigs;
  55.  
  56.       /* Wait for signals */
  57.       sigs = Wait(portmask | winmask);
  58.  
  59.       /* WBClose notification? */
  60.       if (sigs & portmask) {
  61.        struct ScreenNotifyMessage *snm;
  62.  
  63.        /* Get message */
  64.        while (snm = (struct ScreenNotifyMessage *) GetMsg(p)) {
  65.  
  66.         /* Workbench notification? */
  67.         if (snm->snm_Type == SCREENNOTIFY_TYPE_WORKBENCH)
  68.  
  69.          /* Yes, Open/Close event? */
  70.          switch (snm->snm_Value) {
  71.  
  72.           case FALSE: /* WB Close -> close our window */
  73.            if (w) {
  74.             CloseWindow(w);
  75.             w       = NULL;
  76.             winmask = NULL;
  77.            }
  78.            break;
  79.  
  80.           case TRUE:  /* WB Open -> reopen our window */
  81.            if ((w == NULL) && (w = CreateWindow()))
  82.             winmask = 1L << w->UserPort->mp_SigBit;
  83.            break;
  84.          }
  85.  
  86.         /* Reply message */
  87.         ReplyMsg((struct Message *) snm);
  88.        }
  89.       }
  90.  
  91.       /* Window event? */
  92.       if (sigs & winmask) {
  93.        struct IntuiMessage *msg;
  94.  
  95.        /* Handle window events */
  96.        while (msg = (struct IntuiMessage *) GetMsg(w->UserPort)) {
  97.  
  98.         if (msg->Class == IDCMP_CLOSEWINDOW) active = FALSE;
  99.  
  100.         ReplyMsg((struct Message *) msg);
  101.        }
  102.       }
  103.      }
  104.  
  105.      /* Close window */
  106.      CloseWindow(w);
  107.     }
  108.  
  109.     /* Unregister WB client */
  110.     while (!RemWorkbenchClient(handle)) Delay(10);
  111.    }
  112.  
  113.    /* Delete message port */
  114.    DeleteMsgPort(p);
  115.   }
  116.  
  117.   /* Close wbclose.library */
  118.   CloseLibrary(ScreenNotifyBase);
  119.  }
  120. }
  121.